# coding: utf-8
import sys

from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QWidget, QVBoxLayout, QGridLayout, QApplication
from qfluentwidgets import SingleDirectionScrollArea

from a import MicaWindow
from common import OthersIcon
from components import WebCentreImageLabel


class ScrollAreaWidget(SingleDirectionScrollArea):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.widget = QWidget()
        self.gridLayout = QGridLayout(self.widget)
        self.__initWidget()

        # self.addWidget(OthersIcon.Default.path(), 0, 0)
        # self.addWidget(OthersIcon.Default1.path(), 0, 1)
        # self.addWidget(OthersIcon.Default2.path(), 0, 2)
        # self.addWidget(OthersIcon.Default3.path(), 1, 0)
        # self.addWidget(OthersIcon.Default4.path(), 1, 1)
        # self.addWidget(OthersIcon.Default5.path(), 1, 2)
        label = self.addWidget('', 2, 0)
        label.setUrl('https://pic.netbian.com/uploads/allimg/240429/225620-171440258038bf.jpg')

    def __initWidget(self):
        self.setWidget(self.widget)
        self.setWidgetResizable(True)
        self.setStyleSheet('background-color: transparent; border: none;')
        self.gridLayout.setSpacing(20)
        self.gridLayout.setAlignment(Qt.AlignmentFlag.AlignTop)

    def addWidget(self, pixmap: str, row: int, col: int):
        label = WebCentreImageLabel(self)
        label.setImage(pixmap)
        label.setMinimumSize(400, 400)
        label.setBorderRadius(5, 5, 5, 5)
        self.gridLayout.addWidget(label, row, col, 1, 1)
        return label


class Window(MicaWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('图片浏览器')
        self.setWindowIcon(QIcon('resource/logo.png'))

        self.verticalLayout = QVBoxLayout(self)
        self.verticalLayout.setAlignment(Qt.AlignmentFlag.AlignTop)
        self.verticalLayout.setContentsMargins(0, 30, 0, 0)
        self.verticalLayout.addWidget(ScrollAreaWidget(self))


if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Window()
    demo.resize(800, 600)
    demo.show()
    sys.exit(app.exec_())
